import tkinter
from tkinter import *
import loading
import Operation

# 开头

def copy_regiest():
    def Action(win):
        font_show = ('楷体',20)
        label_show = tkinter.Label(win,text='Welcome to 学生管理系统！',font=font_show)
        label_show.place(x=300,y=30)

    #  标签 提示
    def label_show(win):
        Label_show = tkinter.Label(win,text='欢迎注册学生系统!',font=30)
        Label_show.place(x=300,y=120)
        label1 = tkinter.Label(master=win, text='用户名：', font=7)
        label2 = tkinter.Label(master=win, text='密码：', font=7)
        # # 注册用户名
        label1.place(x=350, y=180)
        # 注册密码
        label2.place(x=350, y=220)
        # 再次输入注册密码
        label3 = tkinter.Label(master=win, text='再次输入密码:', font=7)
        label3.place(x=280, y=320)

    def openfile_admine():
        with open(r'D:\admine.txt', 'r', encoding='utf8') as file:
            admine_reader = file.read()
            return admine_reader

    def openfile_students():
        with open(r'D:\students.txt', 'r', encoding='utf8') as file:
            students_reader = file.read()
            return students_reader



    win = tkinter.Tk()
    win.title('This is My TK procedure')
    win.geometry('800x600')

    # 开始
    Action(win)

    # 左侧插入图片
    image1 = PhotoImage(file=r'C:\dell\vx6.png')
    label_left = tkinter.Label(win,image=image1)
    label_left.place(y=100)

    # label 提示
    label_show(win)

    #  注册用户名，
    entry1 = tkinter.Entry(master=win,width=30)
    entry1.place(x=430,y=180)


    #  注册密码
    def pwtishi(event):
        m = StringVar()
        list_box = tkinter.Listbox(win,listvariable=m,height=3,width=22,fg='green')
        for i in ['  ! 不能包括空格','  ! 长度为8-16个字符',' ! 必须包含数字字母符号三种']:
            list_box.insert(END,i)
        list_box.place(x=440,y=250)


    entry2 = tkinter.Entry(master=win,width=30)
    entry2.bind('<Button-1>',pwtishi)
    entry2.place(x=430,y=220)

    # 再次注册密码
    entry3 = tkinter.Entry(win,width=30)
    entry3.place(x=430,y=320)

    Checkbutton1 = tkinter.Checkbutton(win,text='我已阅读并同意相关服务条款和隐私政策',indicatoron='True')
    Checkbutton1.place(x=530,y=340)
    Checkbutton1.select()

    # 选择 注册哪类用户
    def choose_regiest():
        get_choose = r.get()
        admine = Operation.get_text(entry1)
        admine_password = Operation.get_text(entry2)
        font = ('楷体', 15)
        if get_choose=='1':
            reader = openfile_admine()
            if reader == '':
                admine_username = Operation.admin_Register(admine,admine_password)
                admine_username.record()
                label5 = tkinter.Button(win, text='注册成功', font=font, bg='skyblue',state = 'disabled')
                label5.place(x=430, y=510)
            else:
                reader = Operation.reader()
            if admine not in reader:
                admine_username = Operation.admin_Register(admine,admine_password)
                admine_username.record()
                label5 = tkinter.Button(win, text='注册成功', font=font, bg='skyblue',state = 'disabled')
                label5.place(x=430, y=510)
            else:
                label5 = tkinter.Button(win, text='该用户已存在！', font=font, bg='orange',state = 'disabled')
                label5.place(x=430, y=510)
        elif get_choose =='2':
            reader = openfile_students()
            if admine not in reader:
                if reader == None:
                    admine_username = Operation.admin_Register(admine, admine_password)
                    admine_username.record()
                    label5 = tkinter.Button(win, text='注册成功', font=font, bg='skyblue',state = 'disabled')
                    label5.place(x=430, y=510)

                reader = Operation.reader()

                if admine not in reader:
                    admine_username = Operation.admin_Register(admine, admine_password)
                    admine_username.record()
                    label5 = tkinter.Button(win, text='注册成功', font=font, bg='skyblue',state = 'disabled')
                    label5.place(x=430, y=510)
                else:
                    label5 = tkinter.Button(win, text='该用户已存在！', font=font, bg='orange',state = 'disabled')
                    label5.place(x=430, y=510)

        elif get_choose=='3':
            pass

        else:
            label5 = tkinter.Button(win, text='请选择选项', font=font, bg='orange', state='disabled')
            label5.place(x=430, y=510)



    label_Checkbutton = tkinter.Label(win, text='Please  choose', font=('Arial', 12))
    label_Checkbutton.place(x=480, y=380)
    r = tkinter.StringVar()
    r.set(0)
    choose_admin = tkinter.Radiobutton(win, text='系统管理员', variable=r, value='1')
    choose_admin.place(x=460, y=410)
    choose_students = tkinter.Radiobutton(win, text='学生', variable=r, value='2')
    choose_students.place(x=550, y=410)
    choose_chongzhi = tkinter.Radiobutton(win, text='重置', variable=r, value='3')
    choose_chongzhi.place(x=600, y=410)


    def judge():
        get_password1 = Operation.get_text(entry2)
        get_password2 = Operation.get_text(entry3)
        if get_password2 == get_password1:
            choose_regiest()
            label4 = tkinter.Label(win, text='√', fg='green', font='bold')
            label4.place(x=660, y=320)
        else:
            label4 = tkinter.Label(win, text='×', fg='red', font='bold')
            label4.place(x=660, y=320)

    Button1_regiest = tkinter.Button(win,text=' 确认注册 ',font='楷体',command = judge,width=20,bg='skyblue')
    Button1_regiest.place(x=430,y=460)

    Button_load = tkinter.Button(win,text='登录',font='楷体',relief='flat',command=loading.new_window)
    Button_load.place(x=600,y=500)

    win.mainloop()